﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

namespace AnyOffice.general.system.menu
{
    public partial class func_new : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack && (Request.QueryString["menu_id"] != null))
            {
                string str = Request.QueryString["menu_id"].ToString();
                this.ViewState["MenuId"] = str;
                this.txtMenuId.Value = Request.QueryString["menu_id"].ToString();
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                SysFunctionDao dao = new SysFunctionDao();
                if (dao.SelectByMenuId(base.Conn, this.txtMenuId.Value).Rows.Count > 0)
                {
                    this.litMessage.Text = base.ShowPrompt("子菜单项代码已存在！", "func_new.aspx?menu_id=" + this.ViewState["MenuId"].ToString());
                }
                else if (dao.SelectByFuncCode(base.Conn, this.txtFuncCode.Value).Rows.Count > 0)
                {
                    this.litMessage.Text = base.ShowPrompt("子菜单模块路径已存在！", "func_new.aspx?menu_id=" + this.ViewState["MenuId"].ToString());
                }
                else
                {
                    SysFunctionData data = new SysFunctionData();
                    data.MenuId = this.txtMenuId.Value;
                    data.FuncName = this.txtFuncName.Value;
                    data.FuncCode = this.txtFuncCode.Value;
                    data.FuncImg = this.txtFuncImg.Value;
                    dao.Insert(base.Conn, data);
                    this.litMessage.Text = base.ShowMessage("增加成功！") + "<script>parent.menu_list.location.reload();</script>";
                }
            }
        } 

    }
}
